<?php
/**
 * Created by PhpStorm.
 * User: alei
 * Date: 11/5/2017 AD
 * Time: 17:09
 */
namespace App\Models\Mysql\tonggao;

//use Illuminate\Database\Eloquent\Model;
use App\Models\Traits\BaseDBMethod;

class term_detail
{
	use BaseDBMethod;
	//数据库连接配置项，见config/database.php
	const DATABASE_CONF = 'tonggao_mysql';
	//pre_ct_ui 首页轮播图所在表
	const TABLE_NAME = 'term_detail';

	//数据库连接配置项，见config/database.php
	//如果需要用ORM，需要设置此项
//	protected $connection = self::DATABASE_CONF;
	//表名，如果需要用ORM，需要设置此项
//	protected $table = self::TABLE_NAME;

	public static function select($sql)
	{
		return self::getConnObj()->select($sql);
	}

	public static function insert($sql)
	{
		return self::getConnObj()->insert($sql);
	}

	public static function getDataByTermIdArticleIdByPage($termID, $articleID, $size)
	{
		if(0 === $termID || 0 === $articleID) return null;

		//select term_detail.id , term_detail.english,term_detail.tonggao_changed,sentence.seq_no sentence_seq_no, sentence.content sentence_content, sentence.translation sentence_translation from term_detail,sentence where term_detail.article_id=1 and term_detail.term_id=1 and term_detail.sentence_id=sentence.id
		return self::getDBobj(true)
			->select('term_detail.id','term_detail.english','term_detail.tonggao_changed','sentence.seq_no as sentence_seq_no','sentence.content as sentence_content','sentence.translation as sentence_translation')
			->join('sentence', 'term_detail.sentence_id', '=', 'sentence.id')
			->where('term_detail.article_id', '=', $articleID)
			->where('term_detail.term_id', '=', $termID)
			->where('term_detail.has_big_term', '=', 0)
			->orderBy('sentence.last_modify_time', 'desc')
			->paginate($size)
			->toArray();

	}

}